import * as tslib_1 from "tslib";
import { Pipe, Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { of } from 'rxjs';
import { catchError, switchMap } from "rxjs/operators";
import { HttpClient } from '@angular/common/http';
import { DomSanitizer } from '@angular/platform-browser';
export function createTranslateLoader(http, version) {
    var versionSuffix = "";
    if (version) {
        versionSuffix = "?v=" + version;
    }
    return new TranslateHttpLoader(http, '/apps/apporder/df/web/bo-employee-front/employeeform/i18n/', '.json' + versionSuffix);
}
export var lang = { "zh-CHS": { "root-component": "", "root-layout": "", "page-header": "", "header-nav": "", "header-title-container": "", "page-header-title": "", "page-header-toolbar": "", "button-add": "新增", "button-edit": "编辑", "button-save": "保存", "button-cancel": "取消", "main-container": "", "like-card-container": "", "basic-form-component-ref": "", "detail-container": "", "detail-section": "", "Section/detail-section/mainTitle": "", "Section/detail-section/subTitle": "", "detail-tab": "", "jobinfo-tab-page": "工作信息", "jobinfo-component-ref": "", "jobinfo-tab-toolbar": "", "jobinfoAddButton": "新增", "jobinfoRemoveButton": "删除", "basic-form-component": "", "basic-form-section": "", "Section/basic-form-section/mainTitle": "基本信息", "Section/basic-form-section/subTitle": "", "basic-form-layout": "", "code_7b2f03f5_6dgt": "编号", "TextBox/code_7b2f03f5_6dgt/placeHolder": "", "name_8b788a59_326c": "名称", "TextBox/name_8b788a59_326c/placeHolder": "", "remark_87a8db9b_m2hn": "备注", "TextBox/remark_87a8db9b_m2hn/placeHolder": "", "state_f6094b3b_m7k9": "状态", "TextBox/state_f6094b3b_m7k9/placeHolder": "", "organization_efd7f305_vfoh": "组织", "TextBox/organization_efd7f305_vfoh/placeHolder": "", "gender_e593e1a1_ewup": "性别", "TextBox/gender_e593e1a1_ewup/placeHolder": "", "countryOrArea_0f822ec8_5rxf": "所属国家或地区", "TextBox/countryOrArea_0f822ec8_5rxf/placeHolder": "", "location_411a7c80_rtuz": "常驻地", "TextBox/location_411a7c80_rtuz/placeHolder": "", "postID_d9085102_xlsc": "职级", "TextBox/postID_d9085102_xlsc/placeHolder": "", "category_7c8c1521_gi63": "人员类别", "TextBox/category_7c8c1521_gi63/placeHolder": "", "displayName_ed752cbf_gayz": "显示姓名", "TextBox/displayName_ed752cbf_gayz/placeHolder": "", "telephone_00be3451_drfr": "联系电话", "TextBox/telephone_00be3451_drfr/placeHolder": "", "secret_a77111d8_hjht": "密级", "TextBox/secret_a77111d8_hjht/placeHolder": "", "mailbox_a9822261_vy64": "邮箱", "TextBox/mailbox_a9822261_vy64/placeHolder": "", "jobinfo-component": "", "jobinfo-component-layout": "", "dataGrid_jobinfo": "", "DataGrid/dataGrid_jobinfo/lineNumberTitle": "", "DataGrid/dataGrid_jobinfo/OperateEditButton": "编辑", "DataGrid/dataGrid_jobinfo/OperateDeleteButton": "删除", "DataGrid/dataGrid_jobinfo/OperateColumn": "操作", "company_ea7589cc_eq6f": "工作单位", "GridField/company_ea7589cc_eq6f/editor/company_ea7589cc_jefs": "文本", "GridField/company_ea7589cc_eq6f/editor/TextBox/company_ea7589cc_jefs/placeHolder": "", "timeInterval_402bb43e_h45i": "时间区间", "GridField/timeInterval_402bb43e_h45i/editor/timeInterval_402bb43e_l6t2": "文本", "GridField/timeInterval_402bb43e_h45i/editor/TextBox/timeInterval_402bb43e_l6t2/placeHolder": "", "position_72b50570_bpin": "岗位", "GridField/position_72b50570_bpin/editor/position_72b50570_fw9q": "文本", "GridField/position_72b50570_bpin/editor/TextBox/position_72b50570_fw9q/placeHolder": "", "salary_43c48ecf_g89o": "薪资", "GridField/salary_43c48ecf_g89o/editor/salary_43c48ecf_calg": "复选框", "GridField/salary_43c48ecf_g89o/formatter/trueText": "是", "GridField/salary_43c48ecf_g89o/formatter/falseText": "否", "certifier_1e447038_l1vb": "证明人", "GridField/certifier_1e447038_l1vb/editor/certifier_1e447038_w5bj": "文本", "GridField/certifier_1e447038_l1vb/editor/TextBox/certifier_1e447038_w5bj/placeHolder": "", "telephone_0a01ff5e_3zek": "证明人联系方式", "GridField/telephone_0a01ff5e_3zek/editor/telephone_0a01ff5e_dk6o": "文本", "GridField/telephone_0a01ff5e_3zek/editor/TextBox/telephone_0a01ff5e_dk6o/placeHolder": "" } };
var LangPipe = /** @class */ (function () {
    function LangPipe(translate, http) {
        this.translate = translate;
        this.http = http;
    }
    LangPipe.prototype.transform = function (key, langCode, defaultValue) {
        var translateValue = this.translate.instant(key);
        if (translateValue == "JitI18nDefaultValue") {
            return defaultValue ? defaultValue : "";
        }
        return translateValue;
    };
    LangPipe = tslib_1.__decorate([
        Pipe({ name: 'lang' }),
        tslib_1.__metadata("design:paramtypes", [TranslateService, HttpClient])
    ], LangPipe);
    return LangPipe;
}());
export { LangPipe };
var SafeHtmlPipe = /** @class */ (function () {
    function SafeHtmlPipe(sanitizer) {
        this.sanitizer = sanitizer;
    }
    SafeHtmlPipe.prototype.transform = function (url) {
        if (!url) {
            url = "";
        }
        return this.sanitizer.bypassSecurityTrustResourceUrl(url);
    };
    SafeHtmlPipe = tslib_1.__decorate([
        Pipe({ name: 'safeHtml' }),
        tslib_1.__metadata("design:paramtypes", [DomSanitizer])
    ], SafeHtmlPipe);
    return SafeHtmlPipe;
}());
export { SafeHtmlPipe };
var LangService = /** @class */ (function () {
    function LangService(translate) {
        this.translate = translate;
    }
    LangService.prototype.transform = function (key, langCode, defaultValue) {
        var translateValue = this.translate.instant(key);
        if (translateValue == "JitI18nDefaultValue") {
            return defaultValue ? defaultValue : "";
        }
        return translateValue;
    };
    LangService.prototype.getCurrentLanguage = function () {
        return this.translate.currentLang;
    };
    LangService = tslib_1.__decorate([
        Injectable(),
        tslib_1.__metadata("design:paramtypes", [TranslateService])
    ], LangService);
    return LangService;
}());
export { LangService };
var TranslateResolveService = /** @class */ (function () {
    function TranslateResolveService(translate, http) {
        this.translate = translate;
        this.http = http;
        translate.defaultLang = 'zh-CHS';
        translate.setTranslation('zh-CHS', lang['zh-CHS']);
    }
    TranslateResolveService.prototype.resolve = function (route, state) {
        var _this = this;
        var langCode = localStorage.getItem('languageCode');
        if (!langCode) {
            langCode = "zh-CHS";
        }
        if (langCode == "zh-CHS" || (this.translate.defaultLang === langCode && this.translate.currentLoader == createTranslateLoader(this.http, null))) {
            this.translate.setTranslation('zh-CHS', lang['zh-CHS']);
            return of(this.translate[langCode]);
        }
        else {
            var httpOb = this.http.get("/apps/apporder/df/web/bo-employee-front/version.json?v=" + new Date().getTime()).pipe(switchMap(function (data) {
                var currentVersion = null;
                if (data instanceof Array) {
                    var versionKey_1 = "employeeform/" + langCode + ".json";
                    data.forEach(function (item) {
                        if (item.category == "i18n" && item.key == versionKey_1) {
                            currentVersion = item.value;
                        }
                    });
                }
                _this.translate.defaultLang = langCode;
                _this.translate.currentLang = langCode;
                _this.translate.currentLoader = createTranslateLoader(_this.http, currentVersion);
                var tran = _this.translate.getTranslation(langCode).pipe(catchError(function (err) {
                    console.error("read resource file failed,please check!!! " + err);
                    return of(err);
                }));
                return tran;
            }));
            return httpOb;
        }
    };
    TranslateResolveService = tslib_1.__decorate([
        Injectable(),
        tslib_1.__metadata("design:paramtypes", [TranslateService, HttpClient])
    ], TranslateResolveService);
    return TranslateResolveService;
}());
export { TranslateResolveService };
